package com.gzy.cbrsystem.core.insomnia;

import java.lang.reflect.Field;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

import com.gzy.cbrsystem.core.VectorAverage;
import com.gzy.cbrsystem.core.interfaces.CaseRepresentation;
import com.gzy.cbrsystem.core.interfaces.SimilarityCalculation;
import com.gzy.cbrsystem.core.interfaces.VectorSimilarity;

public class InsomniaSimilarity implements SimilarityCalculation {
	
	CaseRepresentation config;
	VectorSimilarity insomniaSim;
	
	public Object getConfig() {
		return config;
	}
	public void setConfig(CaseRepresentation config) {
		this.config = config;
	}
	public VectorSimilarity getInsomniaSim() {
		return insomniaSim;
	}
	public void setInsomniaSim(VectorSimilarity insomniaSim) {
		this.insomniaSim = insomniaSim;
	}
	public void init()
	{
		insomniaSim= new VectorAverage();
		
	}
	public double CalculateSimilarity(Object a, Object b) {
		InsomniaCaseDescription ia=(InsomniaCaseDescription)a;
		InsomniaCaseDescription ib=(InsomniaCaseDescription)b;
		List<Field> atts = config.getAttributes();
		Map<Field,Double> weights =  config.getWeights();
		SimilarityCalculation attSim = config.getAttSimilarity();
		double sim=insomniaSim.calculate(ia, ib, atts, weights, attSim);
		DecimalFormat format = new DecimalFormat("#.##");
		sim = Double.parseDouble(format.format(sim));
		return sim;
	}
	
	public void setConfig(Object object) {
		this.config=(CaseRepresentation)object;
		
	}

}
